﻿using DG.Tweening;
using TMPro;
using UnityEngine;

public class HintItem : USaBehaviour
{
    [SerializeField]
    private RectTransform m_AnimaRoot;
    [SerializeField]
    private CanvasGroup m_CanvasGroup;
    [SerializeField]
    private TextMeshProUGUI m_HintLabel;

    public void SetItem(string hintText, float duration)
    {
        m_HintLabel.text = hintText;
        PlayShowAnima(duration);
    }

    private void PlayShowAnima(float duration)
    {
        var sequence = DOTween.Sequence();
        sequence.Append(m_AnimaRoot.DOScale(1f, 0.1f)
            .OnStart(() => m_AnimaRoot.localScale = Vector3.one * 0.9f)
            .OnComplete(() => m_AnimaRoot.localScale = Vector3.one)
            .SetEase(Ease.OutBack));
        sequence.Join(m_CanvasGroup.DOFade(1, 0.1f)
            .OnStart(() => m_CanvasGroup.alpha = 0f)
            .OnComplete(() => m_CanvasGroup.alpha = 1f));
        sequence.AppendInterval(duration);
        sequence.Append(m_AnimaRoot.DOScale(0.9f, 0.1f)
            .OnStart(() => m_AnimaRoot.localScale = Vector3.one)
            .OnComplete(() => m_AnimaRoot.localScale = Vector3.one * 0.9f)
            .SetEase(Ease.Linear));
        sequence.Join(m_CanvasGroup.DOFade(0, 0.1f)
            .OnStart(() => m_CanvasGroup.alpha = 1f)
            .OnComplete(() => m_CanvasGroup.alpha = 0f));
    }
}